home *** CD-ROM | disk | FTP | other *** search
- { puttext.pas -- Put text into clipboard }
-
- program PutText;
-
- uses WinTypes, WinProcs, WinCrt, Strings;
-
- const
-
- winCrtClassName = 'TPWinCrt';
-
- var
-
- HWindow: HWnd; { Handle to WinCrt window }
- S: array[0 .. 80] of Char; { String to copy to clipboard }
-
- {- Return true if text at P is copied to clipboard }
- function PutClipText(HWindow: HWnd; P: PChar): Boolean;
- var
- GHandle: THandle;
- GPtr: PChar;
- begin
- PutClipText := false;
- if (P <> nil) and (StrLen(P) > 0) then
- begin
- GHandle := GlobalAlloc(gmem_Moveable, StrLen(P) + 1);
- if GHandle <> 0 then
- begin
- GPtr := GlobalLock(GHandle);
- if GPtr = nil then
- GlobalFree(GHandle)
- else begin
- StrCopy(GPtr, P);
- GlobalUnlock(GHandle);
- if not OpenClipboard(HWindow) then
- GlobalFree(GHandle)
- else begin
- EmptyClipboard;
- SetClipboardData(cf_Text, GHandle);
- CloseClipboard;
- PutClipText := true
- end
- end
- end
- end
- end;
-
- begin
- InitWinCrt; { Registers window class for FindWindow }
- HWindow := FindWindow(winCrtClassName, nil);
- if HWindow = 0 then
- Writeln('*** Unable to find WinCrt''s window handle')
- else begin
- Writeln('Send text to clipboard');
- Writeln('----------------------');
- repeat
- Writeln('Enter text or press Enter to end');
- Write('>');
- Readln(S);
- if PutClipText(HWindow, S) then
- Writeln('Text copied to clipboard')
- else
- Writeln('No text to copy or error')
- until StrLen(S) = 0
- end;
- Write('Type Alt+F4 to close window')
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/25/1991
- ---------------------------------------------------------------}
-